<?php

Yii::import('common.models._base.BaseTblBackendUser');

class TblBackendUser extends BaseTblBackendUser {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public $confirm_password;

    public static function label($n = 1) {
        return Yii::t('app', 'Backend User|Backend Users', $n);
    }

    public function rules() {
        return array(
            array('username,email, password', 'required'),
            array('username', 'unique', 'on' => 'insert', 'message' => Yii::t('validation', 'username has already been taken.')),
            array('email', 'unique', 'on' => 'insert', 'message' => Yii::t('validation', 'Email has already been taken.')),
            array('confirm_password', 'required', 'on' => 'insert'),
            array('email', 'email'),
            array('password', 'length', 'min' => 4, 'on' => 'insert'),
            array('confirm_password', 'compare', 'compareAttribute' => 'password', 'message' => Yii::t("tblBackendUser", "Password and Confirm Password are not same."), 'on' => 'insert'),
            array('id, username, password, activationkey, createtime, lastvisit, superuser, status', 'safe', 'on' => 'search'),
        );
    }

    public static function getLoginUserName($modelUserProfiles) {
        $userId = Yii::app()->user->id;
        $model = UserProfile::model()->findByPk($modelUserProfiles->profile_id);
        echo '<div style="position: absolute;margin:12px 0px 0px 41px;"> ' . $model->first_name . '  ' . $model->last_name . ' profile</div>';
    }

    public static function getUserProfile($userid, $fieldName) {
        $profileDetails = UserProfile::model()->find('user_id=:userid', array(':userid' => $userid));
        $returnValue = ($profileDetails->$fieldName == '') ? 'No data' : $profileDetails->$fieldName;
        return $returnValue;
    }

}